<template>
	<div class="banner">
		<!-- 隐藏菜单 -->
		<div :class="[{'default':show},'slider']">
			<p>
				<router-link to="/">登录</router-link> / <router-link to="/">注册</router-link>
			</p>
			<!-- 搜索 -->
			<form class="search">
				<i class="iconfont icon-fangdajing"></i>
				<input type="text" value="漂亮国" />
			</form>
			<ul>
				<li v-for="item in menus" :key="item.id">
					<router-link :to="item.url">{{item.name}}</router-link>
				</li>
			</ul>
		</div>
		<!-- 主界面 -->
		<div class="main">
			<!-- 顶部 -->
			<div class="banner-top">
				<!-- 城市切换 -->
				<div class="city" @click="jumpCitys()">
					<label>{{cityName}}<i class="iconfont icon-xiajiantou"></i></label>
				</div>
				<!-- 搜索 -->
				<form class="search">
					<i class="iconfont icon-fangdajing"></i>
					<input type="text" placeholder="请输入城市" />
				</form>
				<!-- 导航按钮 -->
				<p class="slide-btn" @click="getShow()">
					<i class="iconfont icon-liebiao"></i>
				</p>
				
			</div>
			<!-- 轮播区域 -->
			<div class="swiper banner-swiper">
				<div class="swiper-wrapper">
					<li class="swiper-slide" v-for="item in imglist" :key="item.id">
						<img :src="require('@/'+item.src)" />
					</li>
				</div>
				 <div class="swiper-pagination"></div><!--分页器。如果放置在swiper外面，需要自定义样式。-->
			</div>
		</div>
	</div>
</template>

<script>
	//引入vue周期函数
	import {onMounted} from 'vue';
	import {mapState} from 'vuex';
	
	import Swiper , {
		Autoplay,
		EffectCoverflow,
		EffectCube,
		Pagination
	} from 'swiper';
	
	// //swiper组件应用配置
	Swiper.use([Autoplay,EffectCoverflow,EffectCube,Pagination]);
	
	export default {
		name:'Banner',
		props:['bannerlist','propbanner_imglist'],
		data(){
			return {
				menus : [],
				show:false,
				imglist:[]
			}
		},
		watch:{
			bannerlist(){
				this.menus = this.bannerlist;
			},
			propbanner_imglist(){
				this.imglist = this.propbanner_imglist;
				new Swiper('.banner-swiper' , {
					//循环播放
					observer:true,
					observerParents:true,
					//设置分页器
					pagination:{
						el : '.swiper-pagination'
					},
					//设置播放项[时间不停止，手指经过不暂停自动]
					autoplay:{
						delay : 3000,
						stopOnLastSlide : false,
						disableOnInteraction:false,
					}
				})
			}
		},
		methods:{
			getShow(){
				this.show = !this.show;
			},
			jumpCitys(){
				this.$router.push({path:'/citys'})
			}
		},
		computed:{
			...mapState(['cityName'])
		}
	}
</script>

<style scoped>
	/* 侧 导航栏 */
	.slider{
		position: absolute;
		left: -6.6rem;
		top: 0;
		z-index: 6;
		background: rgba(62,62,62,0.9);
		height: 100%;
		width: 6.6rem;
	}
	.default{
		left: 0;
		transition: all 1s;
	}
	.slider a{
		text-decoration: none;
		color: white;
	}
	.slider p{
		line-height: 1.3rem;
		text-align: right;
		padding-right: 0.3rem;
		color: white;
		font-size: 0.35rem;
	}
	.slider .search{
		background-color: #3a3a3a;
		border-radius: 0.2rem;
		overflow: hidden;
		line-height: 0.8rem;
		width: 90%;
		margin: 0.35rem auto;
	}
	.slider .search i{
		display: inline-block;
		height: 100%;
		font-size: 0.45rem;
		padding-left: 0.2rem;
		vertical-align: middle;
		color: white;
	}
	.slider .search input{
		background-color: #3a3a3a;
		border: none;
		outline: none;
		width: 80%;
		line-height: 0.8rem;
		text-indent: 0.2rem;
		color: white;
	}
	.slider ul{
		margin: 0.5rem auto 0;
		width: 95%;
	}
	.slider ul li{
		line-height: 1.3rem;
		text-align: left;
		text-indent: 1rem;
		font-size: 0.32rem;
		border-top: 0.04rem solid black;
	}
	.slider ul li:last-child{
		border-top: 0.04rem solid black;
	}
	.slider ul li a{
		display: block;
		width: 100%;
	}
	
	.main{
		position: relative;
		width: 100%;
		background-color: #009798;
		height: 5.6rem;
	}
	/* 顶部样式 */
	.banner-top{
		position: absolute;
		left: 0;
		top: 0.3rem;
		z-index: 5;
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: 100%;
		height: 0.8rem;
	}
	.banner-top .city{
		color: white;
		font-size: 0.35rem;
		line-height: 0.8rem;
		padding-left: 0.3rem;
		padding-right: 0.4rem;
	}
	.banner-top .city i{
		vertical-align: middle;
		padding-left: 0.1rem;
	}
	.banner-top .search{
		flex: 1;
		border-radius: 0.2rem;
		overflow: hidden;
		line-height: 0.8rem;
		background: rgba(255, 255, 255, 0.6);
		backdrop-filter:blur(8px);
	}
	.banner-top .search i{
		display: inline-block;
		height: 100%;
		color: #737373;
		font-size: 0.45rem;
		padding-left: 0.2rem;
		vertical-align: middle;
	}
	.banner-top .search input{
		border: none;
		width: 80%;
		outline: none;
		line-height: 0.8rem;
		text-indent: 0.2rem;
		background: none;
	}
	.banner-top .slide-btn{
		color: white;
		padding-left: 0.4rem;
		padding-right: 0.3rem;
		line-height: 0.8rem;
		vertical-align: middle;
	}
	.banner-swiper{
		width: 100%;
		height: 5.6rem;
	}
	.banner-swiper img{
		width: 100%;
		height: 100%;
	}
	
	/* 穿透 */
	.swiper-pagination :deep(.swiper-pagination-bullet-active){
		background-color: orange;
	}
</style>
